<#include "/public/macro.html">
<div class="uk-layui-form">
	<form class="layui-form" action="/apps/contacts/update.html" method="post" data-refresh="true">
		<input type="hidden" name="id" value="${contacts.id!''}">
		<input type="hidden" name="type" value="${type!''}">
		<input type="hidden" name="p" value="${p!''}">
		<input type="hidden" name="typename" value="${typename!''}">
		<input type="hidden" name="contactstype" value="${contactstype!''}">
		<input type="hidden" name="nowUrl" value="${nowUrl!''}">
		<div class="layui-collapse">
			<div class="layui-colla-item">
				<h2 class="layui-colla-title">基本信息</h2>
				<div class="layui-colla-content layui-show">
					<div class="layui-form-item">
						<div class="layui-inline">
							<label class="layui-form-label">获得时间：</label>
							<div class="layui-input-inline">
								<input type="text" name="touchtime" id="getdate" value="<#if contacts.touchtime??>${contacts.touchtime?string('yyyy-MM-dd')}</#if>" readOnly="readOnly" lay-verify="date" autocomplete="off"
									class="layui-input">
								<i class="layui-icon" style="position: absolute;right: 3px;top: 6px;font-size: 25px;">&#xe637;</i>
							</div>
						</div>
						<div class="layui-inline">
							<font color="red">*（必填项）</font> (您得到此联系人的时间)
						</div>
					</div>
					<div class="layui-form-item">
						<div class="layui-inline">
							<label class="layui-form-label">类别：</label>
							<div class="layui-input-inline">
								<div class="layui-input-block" style="width:220px;">
								<input type="radio" name="ctype" value="contacts" title="联系人" <#if (contacts?? && contacts.ctype=='contacts') || !contacts.ctype??>checked</#if> lay-filter="ctype">
								<input type="radio" name="ctype" value="customer" title="客户" <#if contacts?? && contacts.ctype=='customer'>checked</#if> lay-filter="ctype">
   								</div>
							</div>
						</div>
						<div class="layui-inline uckefu-inline" id="ckinddiv" <#if contacts?? && contacts.ctype!='contacts'>style="display: none;"</#if>>
							<label class="layui-form-label" style="line-height: 35px;">类型：</label>
							<div class="layui-input-inline" style="width:218px;margin-right:0px;padding-top:9px;">
								<#if contacts.ckind?? && contacts.ckind != ''>
								<@select "com.dic.contacts.ckind" "ckind" contacts.ckind!'' "lay-ignore ' "/>
								<#else>
								<@select "com.dic.contacts.ckind" "ckind" "" "lay-ignore"/>
								</#if>
							</div>
						</div>
					</div>
					<div class="layui-form-item">
						<div class="layui-inline " >
							<label class="layui-form-label" style="line-height: 35px;">联系人状态：</label>
							<div class="layui-input-inline" style="width:218px;margin-right:0px;padding-top:9px;">
								<#if contacts.business?? && contacts.business != ''>
								<@select "com.dic.contacts.business" "business" contacts.business!'' "lay-ignore ' "/>
								<#else>
								<@select "com.dic.contacts.business" "business" "" "lay-ignore"/>
								</#if>
							</div>
						</div>
						
						<div class="layui-inline  uckefu-inline" style="margin-left: 122px;">
							<label class="layui-form-label">项目：</label>
							<div class="layui-input-inline">
								 <select name="itemid" >
							        <option value="">请选择所属项目</option>
							       	<#if contactsItemList?? && contactsItemList?size gt 0>
										<#list contactsItemList as item>
											<option value="${item.id!''}" <#if contacts?? && contacts.itemid == item.id >selected</#if>>${item.name!''}</option>
										</#list>			       	
							       	</#if>	
							      </select>
							</div>
						</div>
						<!-- <div class="layui-inline uckefu-inline">
							<label class="layui-form-label" style="padding-left: 0;">业务需求说明：</label>
							<div class="layui-input-inline">
								<input type="text" name="busmemo" value="${contacts.busmemo!''}"  autocomplete="off" class="layui-input">
							</div>
						</div> -->	
					</div>
					<div class="layui-form-item">
						<div class="layui-inline">
							<label class="layui-form-label">联系人说明：</label>
							<div class="layui-input-inline" style="width: 664px;">
								<textarea name="busmemo" placeholder="请输入内容" class="layui-textarea" style="resize:none;">${contacts.busmemo!''}</textarea>
							</div>
						</div>
					</div>
					<!-- <div class="layui-form-item">
						<div class="layui-inline">
							<label class="layui-form-label">共享联系人：</label>
							<div class="layui-input-inline" style="width:auto;">
								<div class="layui-input-block">
									<input type="radio" name="shares" value="none" title="不共享（仅创建人和直属上级可见）" <#if contacts?? && contacts.shares !='all'>checked</#if>> 
									<input type="radio" name="shares" value="all" title="所有人" <#if contacts?? && contacts.shares =='all'>checked</#if>>
									
									<input type="radio" name="shares" value="1" title="指定人员或部门" checked>
									
								</div>
							</div>
						</div>
						
					</div> -->
				</div>
			</div>
			<div class="layui-colla-item" id="customer" <#if contacts?? && contacts.ctype!='customer'>style="display: none;"</#if>>
				<h2 class="layui-colla-title">企业信息</h2>
				<div class="layui-colla-content layui-show">
					<div class="layui-form-item">
						<div class="layui-inline">
							<label class="layui-form-label" >客户名称：</label>
							<div class="layui-input-inline">
								<input type="text" name="cusname" value="${contacts.cusname!''}"  autocomplete="off"
									class="layui-input">
							</div>
						</div>
						<div class="layui-inline">
							<font color="red">*（必填项）</font>
						</div>
					</div>
					
					<div class="layui-form-item">
						<div class="layui-inline">
							<label class="layui-form-label">联系电话：</label>
							<div class="layui-input-inline">
								<input type="text" name="cusphone" value="${contacts.cusphone!''}" lay-verify="entphone" autocomplete="off"
									class="layui-input">
							</div>
						</div>
						<div class="layui-inline uckefu-inline">
							<label class="layui-form-label">电子邮件：</label>
							<div class="layui-input-inline">
								<input type="text" name="cusemail" value="${contacts.cusemail!''}" lay-verify="entemail" autocomplete="off" class="layui-input">
							</div>
						</div>
					</div>
					
					<div class="layui-form-item">
						<div class="layui-inline">
							<label class="layui-form-label">城市：</label>
							<div class="layui-input-inline" style="width:80px;">
								<@select "com.dic.address.area" "cusprovince" contacts.cusprovince "lay-ignore" "width:85px;"/>
							</div>
						</div>
						<div class="layui-inline">
							<div class="layui-input-inline" style="width:80px;" id="contacts_cuscity">
								<@select contacts.cuscity+".subdic" "cuscity" contacts.cuscity "lay-ignore" "width:86px;"/>
							</div>
						</div>
						<div class="layui-inline">
							<div class="layui-input-inline" style="width:80px;" id="contacts_cusarea">
								<@select contacts.cusarea+".subdic" "cusarea" contacts.cusarea "lay-ignore" "width:86px;"/>
							</div>
						</div>
					</div>
					
					<div class="layui-form-item">
						<div class="layui-inline">
							<label class="layui-form-label">客户地址：</label>
							<div class="layui-input-inline" style="width: 664px;">
								<input type="text" name="cusaddress" value="${contacts.cusaddress!''}" autocomplete="off" class="layui-input">
							</div>
						</div>
					</div>
					
					<div class="layui-form-item">
						<div class="layui-inline">
							<label class="layui-form-label">客户类型：</label>
							<div class="layui-input-inline">
								<@select "com.dic.contacts.entype" "ekind" contacts.ekind "lay-ignore"/>
							</div>
						</div>
						<div class="layui-inline uckefu-inline">
							<label class="layui-form-label">客户级别：</label>
							<div class="layui-input-inline">
								<@select "com.dic.contacts.elevel" "elevel" contacts.elevel "lay-ignore"/>
							</div>
						</div>
					</div>
					
					<div class="layui-form-item">
						<div class="layui-inline">
							<label class="layui-form-label">客户来源：</label>
							<div class="layui-input-inline">
								<@select "com.dic.contacts.esource" "esource" contacts.esource "lay-ignore"/>
							</div>
						</div>
						<div class="layui-inline uckefu-inline">
							<label class="layui-form-label">成熟度：</label>
							<div class="layui-input-inline">
								<@select "com.dic.contacts.maturity" "maturity" contacts.maturity "lay-ignore"/>
							</div>
						</div>
					</div>
					
					<div class="layui-form-item">
						<div class="layui-inline">
							<label class="layui-form-label">行业：</label>
							<div class="layui-input-inline">
								<@select "com.dic.contacts.industry" "industry" contacts.industry "lay-ignore"/>
							</div>
						</div>
						<div class="layui-inline uckefu-inline">
							<label class="layui-form-label">客户状态：</label>
							<div class="layui-input-inline">
								<@select "com.dic.contacts.validstatus" "cusvalidstatus" contacts.cusvalidstatus "lay-ignore"/>
							</div>
						</div>
					</div>
					
					<div class="layui-form-item">
						<div class="layui-inline">
							<label class="layui-form-label">客户说明：</label>
							<div class="layui-input-inline" style="width: 664px;">
								<textarea name="cusdescription" placeholder="请输入内容" class="layui-textarea" style="resize:none;">${contacts.cusdescription!''}</textarea>
							</div>
						</div>
					</div>
				</div>
			</div>
			<div class="layui-colla-item">
				<h2 class="layui-colla-title">联系人信息</h2>
				<div class="layui-colla-content layui-show">
					<div class="layui-form-item">
						<div class="layui-inline">
							<label class="layui-form-label" id="cusname">联系人名称：</label>
							<div class="layui-input-inline">
								<input type="text" name="name" value="${contacts.name!''}" required lay-verify="required" autocomplete="off"
									class="layui-input">
							</div>
						</div>
						<div class="layui-inline">
							<font color="red">*（必填项）</font>
						</div>
					</div>
					<div class="layui-form-item">
						<div class="layui-inline">
							<label class="layui-form-label">性别：</label>
							<div class="layui-input-inline">
								<div class="layui-input-block" style="width:220px;">
									<input type="radio" name="gender" value="1" title="男" <#if contacts?? && contacts.gender =='1'>checked</#if>>
      								<input type="radio" name="gender" value="0" title="女" <#if contacts?? && contacts.gender =='0'>checked</#if>>
      								<input type="radio" name="gender" value="-1" title="未知" <#if contacts?? && (contacts.gender !='1' && contacts.gender !='0')>checked</#if>>
								</div>
							</div>
						</div>
						<div class="layui-inline uckefu-inline">
							<label class="layui-form-label">生日：</label>
							<div class="layui-input-inline">
								<input type="text" id="cbirthday" name="cbirthday" value="<#if contacts.cbirthday?? && contacts.cbirthday?length gt 10>${contacts.cbirthday?substring(0,10)}<#else>${contacts.cbirthday!''}</#if>" autocomplete="off"
									class="layui-input">
								<i class="layui-icon" style="position: absolute;right: 3px;top: 6px;font-size: 25px;">&#xe637;</i>
							</div>
						</div>
					</div>
					
					<div class="layui-form-item">
						<div class="layui-inline">
							<label class="layui-form-label">联系电话：</label>
							<div class="layui-input-inline">
								<input type="text" name="phone"  lay-verify="entphone" value="${contacts.phone!''}" autocomplete="off"
									class="layui-input">
							</div>
						</div>
						<div class="layui-inline uckefu-inline">
							<label class="layui-form-label">手机号：</label>
							<div class="layui-input-inline">
								<input type="text" name="mobileno"  value="${contacts.mobileno!''}" autocomplete="off" class="layui-input">
							</div>
						</div>
					</div>
					
					<div class="layui-form-item">
						<div class="layui-inline">
							<label class="layui-form-label">城市：</label>
							<div class="layui-input-inline" style="width:80px;">
								<@select "com.dic.address.area" "province" contacts.province "lay-ignore" "width:85px;"/>
							</div>
						</div>
						<div class="layui-inline">
							<div class="layui-input-inline" style="width:80px;" id="contacts_city">
								<@select contacts.city+".subdic" "city" contacts.city "lay-ignore" "width:86px;"/><!-- 二级字典，不存在的 CODE -->
							</div>
						</div>
						<div class="layui-inline">
							<div class="layui-input-inline" style="width:80px;" id="contacts_area">
								<@select contacts.area+".subdic" "area" contacts.area "lay-ignore" "width:86px;"/><!-- 二级字典，不存在的 CODE -->
							</div>
						</div>
						
					</div>
					
					<div class="layui-form-item">
						<div class="layui-inline">
							<label class="layui-form-label">联系人地址：</label>
							<div class="layui-input-inline" style="width: 664px;">
								<input type="text" name="address" autocomplete="off" value="${contacts.address!''}" class="layui-input">
							</div>
						</div>
					</div>
					<div class="layui-form-item">
						<div class="layui-inline">
							<label class="layui-form-label">微信：</label>
							<div class="layui-input-inline">
								<input type="text" name="weixin"  lay-verify="weixin" autocomplete="off" value="${contacts.weixin!''}"
									class="layui-input">
							</div>
						</div>
						<div class="layui-inline uckefu-inline">
							<label class="layui-form-label">QQ：</label>
							<div class="layui-input-inline">
								<input type="text" name="qqcode"   lay-verify="qqcode" autocomplete="off" value="${contacts.qqcode!''}" class="layui-input">
							</div>
						</div>
					</div>
					<div class="layui-form-item">
						<div class="layui-inline">
							<label class="layui-form-label">微博：</label>
							<div class="layui-input-inline">
								<input type="text" name="weibo"  lay-verify="weixin" value="${contacts.weibo!''}" autocomplete="off"
									class="layui-input">
							</div>
						</div>
						<div class="layui-inline uckefu-inline">
							<label class="layui-form-label">电子邮件：</label>
							<div class="layui-input-inline" style="margin-left:5px;">
								<input type="text" name="email" lay-verify="entemail" value="${contacts.email!''}" autocomplete="off" class="layui-input">
							</div>
						</div>
					</div>



					<div class="layui-form-item">
						<div class="layui-inline">
							<label class="layui-form-label">所属单位：</label>
							<div class="layui-input-inline" style="position: relative;">
								<input type="hidden" id="parent" name="cusorgan" value="<#if organData??>${organData.id}<#else>0</#if>">
								<input type="text" name="parentname" id="parentname" required value="<#if organData??>${organData.name}<#elseif area??>${area.name!''}<#else>组织机构</#if>"  autocomplete="off" readOnly="readonly" onClick="showMenu();"
									   class="layui-input">
								<i class="layui-icon" style="position: absolute;right: 3px;top: 6px;font-size: 25px;${systemConfig.color!'color:#0096C4;'}" onClick="showMenu()">&#xe631;</i>
								<div id="menuContent" style="display:none; position: absolute;z-index:10000;width: 218px;height: 198px;" class="ukefu-ztree">
									<ul id="organTree" class="ztree" style="width:208px;height: 188px;"></ul>
								</div>
							</div>
						</div>
					</div>



					<!-- <div class="layui-form-item">
						<div class="layui-inline">
							<label class="layui-form-label">联系人说明：</label>
							<div class="layui-input-inline" style="width: 664px;">
								<textarea name="memo" placeholder="请输入内容" class="layui-textarea" style="resize:none;">${contacts.memo!''}</textarea>
							</div>
						</div>
					</div> -->
				</div>
			</div>
			<div class="layui-colla-item">
				<h2 class="layui-colla-title">联系人扩展信息</h2>
				<div class="layui-colla-content layui-show">
					<#if contacts.extinfo??>
						<#assign extinfoValues = contacts.extinfo?eval /> 
					</#if>
					<#if bussOpList??>
						<#list bussOpList as bussOp>
							<#if bussOp.iconstr??>
							<div class="layui-form-item">
								<div class="layui-inline">
									<label class="layui-form-label">${bussOp.name!''}：</label>
									<div class="layui-input-inline">
											<#if bussOp.iconstr == 'input'>
												<input type="text" name="${bussOp.code!''}" value="${extinfoValues[bussOp.code!'']}" autocomplete="off" class="layui-input">
											<#elseif bussOp.iconstr == 'select'>
												<select name="${bussOp.code!''}" >
											        <option value="">请选择${bussOp.name!''}</option>
											       	<#list uKeFuDic[(bussOp.id!'') + '.subdicid'] as dic>
											       		<option value="${dic.id!''}" <#if extinfoValues[bussOp.code!''] == dic.id>selected</#if>>${dic.name!''}</option>
											       	</#list>	
											     </select>
											<#elseif bussOp.iconstr == 'radio'>
												<#list uKeFuDic[(bussOp.id!'') + '.subdicid'] as dic>
													<input type="radio" name="${bussOp.code!''}" value="${dic.code!''}" title="${dic.name!''}" <#if extinfoValues[bussOp.code!''] == dic.code>checked</#if>>
												</#list>
											<#elseif bussOp.iconstr == 'checkbox'>
												 <input type="checkbox" name="${bussOp.code!''}" lay-skin="switch" value="1" lay-text="是|否" <#if extinfoValues[bussOp.code!''] == "1">checked="checked"</#if>>
											</#if>
									</div>
								</div>
							</div>
							</#if>
						</#list>
					</#if>
				</div>
			</div>
		</div>

		<div class="layui-form-button">
			<div class="layui-button-block">
				<button class="layui-btn" lay-submit lay-filter="formDemo">立即提交</button>
				<button type="reset" class="layui-btn layui-btn-primary">重置</button>
			</div>
		</div>
	</form>
</div>

<script>
	//Demo
	$('#province').change(function(){
		loadURL('/res/dic.html?id='+$(this).val()+"&name=city&attr=lay-ignore&style=width:85px;display:inline-block;" , '#contacts_city');
		document.getElementById("area").options.length = 1;
	})
	$('#contacts_city').change(function(){
		loadURL('/res/dic.html?id='+$('#city_text').val()+"&name=area&attr=lay-ignore&style=width:85px;display:inline-block;" , '#contacts_area');
	});
	$('#cusprovince').change(function(){
		loadURL('/res/dic.html?id='+$(this).val()+"&name=cuscity&attr=lay-ignore&style=width:85px;display:inline-block;" , '#contacts_cuscity');
		document.getElementById("cusarea").options.length = 1;
	})
	$('#contacts_cuscity').change(function(){
		loadURL('/res/dic.html?id='+$('#cuscity_text').val()+"&name=cusarea&attr=lay-ignore&style=width:85px;display:inline-block;" , '#contacts_cusarea');
	});
	layui.use('form', function() {
		var form = layui.form;
		form.render(); //更新全部
		form.verify({
			entphone: function(value){
				if(value!="" && !new RegExp(/^(0\d{2,3}-{0,1}\d{5,8}(-{0,1}\d{3,5}){0,1})|(((1[0-9][0-9])|(14([0-3]|[5-9]))|(15([0-3]|[5-9]))|(16([0-3]|[5-9]))|(17([0-3]|[5-9]))|(18([0-3]|[5-9]))|(19[0-9]))\d{8})$/).test(value)){
			      return '请输入正确的电话号码';
			    }
			},
			entemail: function(value){
			    if(value!="" && !new RegExp(/^([a-zA-Z0-9_-])+@([a-zA-Z0-9_-])+(.[a-zA-Z0-9_-])+/).test(value)){
			      return '请输入正确的电子邮箱地址';
			    }
			}
		});  
		form.on('radio(ctype)', function(data){
			  if(data.value=="contacts"){
				  $("#customer").hide();
				  $("#ckinddiv").show();
			  }else{
				  $("#customer").show();
				  $("#ckinddiv").hide();
			  }
		}); 
	});
	layui.use('element', function(){
		var element = layui.element;
	});
	layui.use('laydate', function() {
		var laydate = layui.laydate;

		var date = {
			min : '1950-01-01 00:00:00',
			istoday : false
		};

		laydate.render({ 
			elem: '#getdate' ,
			format:"yyyy-MM-dd",
			max:0
		});

		laydate.render({ 
			elem: '#cbirthday',
			format:"yyyy-MM-dd",
			max:0 
		});

	});
</script>




<script type="text/javascript">
	var setting = {
		data: {
			simpleData: {
				enable: true
			}
		},
		callback: {
			onClick: onClick,
			beforeClick: beforeClick
		}
	};

	function beforeClick(treeId, treeNode) {
		var event = window.event || arguments.callee.caller.arguments[0];
		var zTree = $.fn.zTree.getZTreeObj("organTree"),
				nodes = zTree.getSelectedNodes();
		var allow = true , lastnode ;
		for (var i=0, l=nodes.length; i<l; i++) {
			lastnode = nodes[i].type ;
			if(nodes[i].organ && (nodes.length >= 1 && (event.ctrlKey || event.shiftKey))){
				allow = false ; break ;
			}
		}
		if(lastnode != treeNode.type && (event.ctrlKey || event.shiftKey)){
			allow = false ;
		}

		if (allow == false) {
			top.layer.alert("组织机构不能点选多个上级机构，也不能同时选择地区和机构", {icon: 3});
			return false;
		} else {
			return true;

		}
	}

	function onClick(e, treeId, treeNode) {
		var event = window.event || arguments.callee.caller.arguments[0];
		var zTree = $.fn.zTree.getZTreeObj("organTree"),
				nodes = zTree.getSelectedNodes(),
				v = "" , value = "";
		nodes.sort(function compare(a,b){return a.id-b.id;});
		for (var i=0, l=nodes.length; i<l; i++) {
			v += nodes[i].name + ",";
			if(value != ""){
				value = value + "," ;
			}
			value = nodes[i].id ;
		}
		if (v.length > 0 ) v = v.substring(0, v.length-1);
		if(treeNode.type == "area"){
			$("#parentname").attr("value", v);
			$("#parent").attr("value", "0");
		}else{
			$("#parentname").attr("value", v);
			$("#parent").attr("value", value);
		}
		if (!event.ctrlKey && !event.shiftKey) {
			hideMenu() ;
		}
	}


	var zNodes =[
		{ id:'0', pId:'00', name:"组织机构", open:true , organ : true, type : "organ"}
		<#if organList??>
			<#list organList as organ>
			,{ id:'${organ.id!''}', pId:'${organ.parent!'0'}', name:"${organ.name!''}", open:true , organ : true , type : "organ",  icon:"/images/dept.png" }
	</#list>
	</#if>
	];
	$(document).ready(function(){
		var ztree = $.fn.zTree.init($("#organTree"), setting, zNodes);
		<#if organData??>
			var node = ztree.getNodeByParam('id', '${organData.id!''}');
		ztree.selectNode(node);
	</#if>
		<#if area??>
			var node = ztree.getNodeByParam('id', '${area.id!''}');
		ztree.selectNode(node);
	</#if>
	});
	function showMenu() {
		$("#menuContent").css({left:"0px", top:"38px"}).show();

		$("body").bind("mousedown", onBodyDown);
	}
	function hideMenu() {
		$("#menuContent").hide();
		$("body").unbind("mousedown", onBodyDown);
	}
	function onBodyDown(event) {
		if (!(event.target.id == "menuBtn" || event.target.id == "menuContent" || $(event.target).parents("#menuContent").length>0)) {
			hideMenu();
		}
	}

</script>